using System.Drawing;
using System.Drawing.Drawing2D;
using CloudShot.Utils;
using CloudShot.Utils.Drawings;

namespace CloudShot.Editor.CanvasFigures
{
  /// <summary>
  ///   Rectangle graphic object
  /// </summary>
  public class CanvasRectangle : CanvasRectangleBase
  {
    public CanvasRectangle() : this(0, 0, 1, 1) {}

    public CanvasRectangle(int x, int y, int width, int height) : base(x, y, width, height) {}

    protected override CanvasObject CloneIntrenal()
    {
      var clone = new CanvasRectangle();
      SetCloneProperties(clone);
      return clone;
    }

    /// <summary>
    ///   Draw rectangle
    /// </summary>
    /// <param name="graphics"></param>
    public override void Draw(Graphics graphics)
    {
      Rectangle rect = Rectangle.GetNormalizedRectangle();
      
      using(Brush brush = CreateBackBrush())
      using(Pen pen = CreateBorderPen())
      using (var path = new GraphicsPath())
      {
        path.AddRectangle(rect);
        path.CloseAllFigures();

        GraphicsState state = graphics.Save();

        graphics.PixelOffsetMode = PixelOffsetMode.None;
        graphics.SmoothingMode = SmoothingMode.None;

        if (LineType != LineType.None)
        {
          graphics.DrawSmallShadow(path, pen);
        }

        graphics.FillPath(brush, path);

        if (LineType != LineType.None)
        {
          graphics.DrawPath(pen, path);
        } 

        graphics.Restore(state);
      }
    }
  }
}